package com.example.myweather.tools

import java.io.IOException

import okhttp3.MediaType
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.RequestBody
import okhttp3.Response

object HttpUtils {
    private val JSON = MediaType.parse("application/json; charset=utf-8")
    private val client = OkHttpClient()

    //    public static Response post(String url, String json) throws IOException {
    //        RequestBody body = RequestBody.create(JSON, json);
    //        Request request = new Request.Builder()
    //                .url(url)
    //                .post(body)
    //                .build();
    //        Response response = client.newCall(request).execute();
    //        return response;
    //    }
    //
    //    public static Response get(String url) throws IOException {
    //        Request request = new Request.Builder()
    //                .url(url)
    //                .build();
    //        Response response = client.newCall(request).execute();
    //        return response;
    //    }

    fun sendOkHttpRequest(address: String, callback: okhttp3.Callback) {
        val client = OkHttpClient()
        val request = Request.Builder()
                .url(address)
                .build()
        client.newCall(request).enqueue(callback)
    }
}
